package com.neoCalf.neoCommon.enums;

import com.neoCalf.neoCommon.utils.DataTool;
import lombok.Getter;


@Getter
public enum UserContactTypeEnum {
    USER(0, "U", "用户"),
    GROUP(1, "G", "群"),
    ROBOT(2, "R", "机器人"),
    SYSTEM(3, "S", "系统");

    private final int type;
    private final String prefix;
    private final String description;

    UserContactTypeEnum(int type, String prefix, String description) {
        this.type = type;
        this.prefix = prefix;
        this.description = description;
    }

    public static UserContactTypeEnum getByPrefix(String prefix) {
        if (!DataTool.isStrLegal(prefix)) {
            return null;
        }
        for (UserContactTypeEnum typeEnum : UserContactTypeEnum.values()) {
            if (typeEnum.getPrefix().equals(prefix)) {
                return typeEnum;
            }
        }
        return null;
    }

    public static UserContactTypeEnum getByType(Integer type) {
        if (type == null) {
            return null;
        }
        for (UserContactTypeEnum typeEnum : UserContactTypeEnum.values()) {
            if (type.equals(typeEnum.getType())) {
                return typeEnum;
            }
        }
        return null;
    }
}
